<%@ page import="com.wl.shixun2.dao.ProductDAO" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String idParam = request.getParameter("id");
    String message = "";
    
    if (idParam != null && !idParam.trim().isEmpty()) {
        try {
            long id = Long.parseLong(idParam);
            ProductDAO dao = new ProductDAO();
            if (dao.delete(id)) {
                message = "产品删除成功";
            } else {
                message = "产品删除失败";
            }
        } catch (NumberFormatException e) {
            message = "无效的产品ID格式";
        } catch (Exception e) {
            message = "删除产品时出错: " + e.getMessage();
        }
    } else {
        message = "未提供产品ID";
    }

    response.sendRedirect("productList.jsp?message=" + URLEncoder.encode(message, "UTF-8"));
%>